// http 拦截器
import axios from "axios";
import qs from "qs";
import router from "../router/router.js";


const http = axios.create({
    timeout: 5000,
});
http.defaults.withCredentials = true;
http.defaults.headers['Content-type']= 'application/json'

http.interceptors.request.use(
    config => {
        return config
    },
    err => {
        console.log(err)
        // app.config.globalProperties.$loading.hideLoading();
        return Promise.reject(err)
    }
)

http.interceptors.response.use(
    response => {
        switch (response.status) {
            case 200:
                return response.data
                break;
            case 202:
                router.push('/login')
                break;
        }
        console.log(response)
    },
    error => {
        switch (error.response.status) {
            case 202:
                router.push('/login')
                return Promise.reject(error.response.data.data)
                break;
            case 403:

                return Promise.reject(error.response.data.data)
                break;
            // return error.response
            default:
                return Promise.reject(error.response.data.data)
        }
        return error.response
    }
)

export default http;
